package com.woniuxy.controller;

import com.woniuxy.conmon.enums.RedisConst;
import com.woniuxy.pojo.China;
import com.woniuxy.service.ChinaService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/china")
public class ChinaController {

    @Autowired
    ChinaService chinaService;

    @GetMapping("/provinces")
    public ResponseEntity<?>    getAllProvinces(){
        List<China> provinces = chinaService.getAddress(0, RedisConst.PROVINCES);
        return ResponseEntity.ok(provinces);
    }

    @GetMapping("/cities/{provinceId}")
    public ResponseEntity<?> getAllCities(@PathVariable  Integer provinceId){
        List<China> cities = chinaService.getAddress(provinceId,RedisConst.CITIES +":"+provinceId);
        return ResponseEntity.ok(cities);
    }

    @GetMapping("/areas/{cityId}")
    public ResponseEntity<?> getAllAreas(@PathVariable  Integer cityId){
        List<China> areas = chinaService.getAddress(cityId,RedisConst.DISTRICTS+":"+cityId);
        return ResponseEntity.ok(areas);
    }
}
